package com.pagoda.nerp.webapi.controller;

import com.pagoda.nerp.web.services.EHRService;
import com.pagoda.nerp.web.services.HRORGPostService;
import com.pagoda.nerp.web.services.HRUnitService;
import com.pagoda.nerp.web.services.HRZGZDService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import static com.pagoda.nerp.erpgwehrApplication.posttree;

@RestController
public class EHRController {

    @Autowired
    private EHRService ehrService;
    @Autowired
    private HRUnitService hrUnitService;
    @Autowired
    private HRORGPostService hrorgPostService;
    @Autowired
    private HRZGZDService hrzgzdService;
    @Value("${rootid}")
    private String rootid;

    @GetMapping("/update")
    public void updateDB(){
        hrUnitService.updateDBUnit();
        hrorgPostService.updateDBPost();
        hrzgzdService.updateDBEmployee();
        posttree = hrorgPostService.getHRORGPostTree(rootid);
    }

    @GetMapping("/GetHRUnit")
    public String GetHRUnit(@RequestParam(value = "date") String date){
        return ehrService.getHROrgXMLStr(date);
    }

    @GetMapping("/GetWsData")
    public String GetHRZGZD(@RequestParam(value = "date") String date){
        return ehrService.getHRZGZDXMLStr(date);
    }

    @GetMapping("/GetHROrgPost")
    public String GetHROrgPost(@RequestParam(value = "date") String date){
        return ehrService.getHROrgPostXMLStr(date);
    }

    @GetMapping("/GetWsDataERP")
    public String getHRZGZDERP(@RequestParam(value = "date")String date) {
        return ehrService.getHRZGZDERPXMLStr(date);
    }
}
